from flask import Flask
from flask_restful import Api
from gevent import pywsgi

from controller.add_book import AddBook
from controller.query_all_books import QueryAllBooks
from controller.update_book_valid import UpdateBookValid
from controller.add_borrower import AddBorrower
from controller.query_all_borrowers import QueryAllBorrowers
from controller.update_borrower_valid import UpdateBorrowerValid
from controller.borrow_book import BorrowBook
from controller.return_book import ReturnBook
from controller.query_book_his import QueryBookHis

app = Flask(__name__)

api = Api(app)
api.add_resource(AddBook, '/addBook')
api.add_resource(QueryAllBooks, '/queryAllBooks')
api.add_resource(UpdateBookValid, '/updateBookValid')
api.add_resource(AddBorrower, '/addBorrower')
api.add_resource(QueryAllBorrowers, '/queryAllBorrowers')
api.add_resource(UpdateBorrowerValid, '/updateBorrowerValid')
api.add_resource(BorrowBook, '/borrowBook')
api.add_resource(ReturnBook, '/returnBook')
api.add_resource(QueryBookHis, '/queryBookHis')

if __name__ == '__main__':
    # 测试环境启动
    # app.run(host="0.0.0.0", port=5000)
    # 生产环境启动
    server = pywsgi.WSGIServer(('0.0.0.0', 5000), app)
    server.serve_forever()
